//
//  UIColor+CY_RGB.m
//  ViewAdd
//
//  Created by ccy on 2017/5/9.
//  Copyright © 2017年 ccy. All rights reserved.
//

#import "UIColor+CY_RGB.h"

@implementation UIColor (CY_RGB)

+(instancetype)colorWithRed:(NSInteger)red andGreen:(NSInteger)green andBlue:(NSInteger)blue
{
    CGFloat redF = red / 255.0;
    CGFloat greenF = green / 255.0;
    CGFloat blueF = blue / 255.0;
    
    return [[UIColor alloc]initWithRed:redF green:greenF blue:blueF alpha:1];

}


+(instancetype)randomColor
{
    CGFloat redF = arc4random_uniform(256) / 255.0;
    CGFloat greenF = arc4random_uniform(256) / 255.0;
    CGFloat blueF = arc4random_uniform(256) / 255.0;
    
    return [[UIColor alloc]initWithRed:redF green:greenF blue:blueF alpha:1];
}

+(instancetype)ColorWithColorString:(NSString *)colorString
{
    unsigned int r,g,b;
    
    NSString *R =  [colorString substringWithRange:NSMakeRange(0, 2)];
    NSString *G =  [colorString substringWithRange:NSMakeRange(2, 2)];
    NSString *B =  [colorString substringWithRange:NSMakeRange(4, 2)];
    
    [[NSScanner scannerWithString:R] scanHexInt:&r];
    [[NSScanner scannerWithString:G] scanHexInt:&g];
    [[NSScanner scannerWithString:B] scanHexInt:&b];
    return [self colorWithRed:r andGreen:g andBlue:b];
}

@end
